package cn.lcj.basic.service.impl;


import cn.lcj.basic.mapper.BaseMapper;
import cn.lcj.basic.query.BaseQuery;
import cn.lcj.basic.service.IBaseService;
import cn.lcj.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * $
 *
 * @return $
 * @date $ $
 * @description $
 */

@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void del(Long id) {
        baseMapper.del(id);
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }


    @Override
    public PageList<T> queryPage(BaseQuery query) {
        Integer totals = baseMapper.queryCount(query);
        if (totals == 0) {
            return new PageList<>();
        }
        List<T> data = baseMapper.queryPage(query);
        return new PageList<>(totals, data);
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> ids) {
        baseMapper.patchDelete(ids);
    }

   
}
